<?php


namespace app\api\controller;


class Aes
{
    private $key ;
    private $iv;
    public function __construct()
    {
        $this->key=config('app.AesKey');
        $this->iv =config('app.AesIv');
    }

    /**
     * AES-128-ECB加密
     * @param  [type] $data [description]
     * @return [type]       [description]
     */
    public function encrypt($data){

        $res = openssl_encrypt($data,'AES-128-CBC', $this->key, OPENSSL_RAW_DATA, $this->iv);
        return base64_encode($res);
    }
    /**
     * AEC-128-ECB解密
     * @param  [type] $data [description]
     * @return [type]       [description]
     */
    public function decrypt($data){
        $res = base64_decode($data);
        $res = openssl_decrypt($res,'AES-128-CBC', $this->key, OPENSSL_RAW_DATA, $this->iv);
        return $res;
    }
}